
#ifndef _MEMBER_BPOLYSTRIPE_H_
#define _MEMBER_BPOLYSTRIPE_H_

#include <BLineStripe>

#define stripe_member(stripe)		((member_BLineStripe*)((BLineStripe*)stripe)->_ptr)

namespace BWE
{
	struct CornerArc
	{
		BVector			center;
		BVector			axis;
		BVector			direct;
		BReal			radius = 0;
		BReal			length = 0;
		BReal			halfAngle = 0;
		BReal			realRadius = 0;
		BVectorArray	vertices;

		inline void clear()
		{
			center.reset();
			axis.reset();
			direct.reset();
			radius = 0;
			length = 0;
			halfAngle = 0;
			realRadius = 0;
			vertices.clear();
		}
		inline bool closest(const BVector& vertex, BVector& result, BVector& direct, BReal& value)
		{
			BVector vec = vertex - center;
			BVector foot = vertex - axis * vec.dot(axis);
			BVector vperp = (foot - center).normal();
			BReal angle = vperp.angle(this->direct);
			if (this->direct.cross(vperp).dot(axis) < 0)
				angle = -angle;
			if (std::abs(angle) < halfAngle)
			{
				vec = (foot - center).normal();
				result = center + vperp * realRadius;
				direct = axis.cross(vec);
				value = angle / halfAngle * length;
				return true;
			}
			return false;
		}
	};
	class member_BLineStripe
	{
		friend class BLineStripe;
	public:
		member_BLineStripe(BLineStripe* stripe);
		~member_BLineStripe();

		void freshCorner(CornerArc& corner, const BVector& vertex, const BVector& prev, const BVector& next);

		BLineStripe*		boss;
		BReal				thickness;
		bool				closeLoop;
		bool				cornerVisible;
		bool				dirty;
		BReal				length;
		BReal				radius;
		BVectorArrayHolder	vertices;
		BArray<BReal>		lineLengths;
		BArray<CornerArc>	cornerArcs;

	};
}

#endif